package ltd.dujiabao.commonutils;

import com.baomidou.mybatisplus.extension.api.R;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : DuJiabao
 * @Project : online-course-project
 * @Time : 2021/4/18 22:44
 * @Desc :
 */
@Accessors(chain = true)
@Data
public class Result {
  @ApiModelProperty(value = "是否成功")
  private Boolean success;

  @ApiModelProperty(value = "返回码")
  private Integer code;

  @ApiModelProperty(value = "结果信息")
  private String message;

  @ApiModelProperty(value = "返回数据")
  private Map<String, Object> data;

  private Result() {
  }

  public static Result success() {
    Result result = new Result();
    result.setSuccess(true);
    result.setCode(ResultCode.SUCCESS);
    result.setMessage("成功");
    result.setData(new HashMap<>());
    return result;
  }

  public static Result failure() {
    Result result = new Result();
    result.setSuccess(false);
    result.setCode(ResultCode.FAILURE);
    result.setMessage("失败");
    result.setData(new HashMap<>());
    return result;
  }

  public Result addData(String key, Object value) {
    data.put(key, value);
    return this;
  }
}
